let moveItem = document.getElementsByTagName('li');
let $clone = ''
let copynum = 0
let exc = true

for (let i = 0; i < moveItem.length; i++) {
  moveItem[i].setAttribute('id', 'label' + i)
  moveItem[i].ondragstart = function (ev) {
    ev.dataTransfer.setData('Text', this.id)
  }

  /* clone item */
  moveItem[i].onmousedown = function () {
    let $clone = this.cloneNode(true)
    $clone.setAttribute('id', 'clabel' + copynum)
    copynum = copynum + 1
    $('.a-c-r-comEdit').slideUp()

    // 元素开始拖动时，隐藏右侧模块
    this.ondragstart = function () {
      $("#right").find(".web-component").hide()
      $("#right").find(".builder-li").css('background-image', 'url(./css/images/compBg.png)')
      $("#right").find(".builder-li").css('border', '0.04rem solid #000')
      exc = false
    }
    document.getElementById('right').ondrop = function (ev) {
      ev.preventDefault()
      let id = ev.dataTransfer.getData('Text')
          let elem = document.getElementById(id)
      let toElem = ev.toElement.id
        ? ev.toElement.id
        : ev.toElement.parentNode.id
      // console.log(toElem)
      if (toElem == 'right') {
        this.appendChild($clone)
      } else if (toElem == '') {
        // console.log(ev.toElement.parentNode)
        console.log('toElem = ""')
        return
      } else {
        this.insertBefore($clone, document.getElementById(toElem))
      }

      // console.log(ev)

      let comp = '#' + $clone.getAttribute('id') + ''
      $(comp).children('p').remove()
      $(comp).children('.web-component').show()

      bSwiper($(comp))  // link='./js/builderSwiper.js'

      $("#right").find(".web-component").show()
      $("#right").find(".builder-li").css('background', 'rgba(0,0,0,0)')
      $("#right").find(".builder-li").css('border', 'none')
      exc = true
    }
    // 元素结束拖动时，显示右侧模块
    this.ondragend = function () {
      $("#right").find(".web-component").show()
      $("#right").find(".builder-li").css('background', 'rgba(0,0,0,0)')
      $("#right").find(".builder-li").css('border', 'none')
    }
    
  }
  /* /clone item */

}

document.getElementById('right').ondragover = function (ev) {
  ev.preventDefault()
}


function componentCheck () {
  if ($("#right").find(".web-component").attr("display") == 'none') {
    alert('check')
  } else {
    alert('fail')
  }
}